import re
def word_times():
    with open("Walden(1).txt","r",encoding='utf-8') as fp:
        post = str(fp.read())
        #除去特殊字符
        sub_post = re.sub(u"([^\u4e00-\u9fa5\u0030-\u0039\u0041-\u005a\u0061-\u007a])",' ',post)
        words = sub_post.split()
        result = {}
        for word in words:
            if word in result:
                result[word] +=1
            else:
                result[word] = 1
        print(result)
word_times()
